package com.xana.acg.com.view.recycler;

import android.content.Context;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.LayoutHelper;

import net.qiujuer.genius.ui.Ui;


public abstract class VirtualAdapter<T> extends RecyclerAdapter<T>{

    protected LayoutHelper lh;
    public VirtualAdapter(){}
    public VirtualAdapter(LayoutHelper lh){
        this.lh = lh;
    }
    @Override
    protected int getItemViewType(int position, T t) {
        return 0;
    }

    public abstract int getViewType(int viewType);

    public LayoutHelper onCreateLayoutHelper(){
        return lh;
    }

    private static Context ctx;

    @Override
    public ViewHolder<T> onCreateViewHolder(ViewGroup parent, int viewType) {
        if(ctx==null) ctx = parent.getContext();
        return super.onCreateViewHolder(parent, viewType);
    }

    public static int dp(int dp){
        if(ctx!=null)
            return (int) Ui.dipToPx(ctx.getResources(), dp);
        return dp*2;
    }
}
